package com.danger.Presenter;

import android.content.Context;

import com.danger.Model.action.IndexModel;
import com.danger.Model.action.IndexModelImpl;
import com.danger.Model.listener.OnCommonListener;
import com.danger.Util.FileCacheService;
import com.danger.View.CommonView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by danger on 2016/4/23.
 */
public class IndexPresenterImpl implements IndexPresenter {

    private Context context;
    private IndexModel model;
    private CommonView view;

    public IndexPresenterImpl(Context context, CommonView view) {
        this.context = context;
        this.view = view;
        model = new IndexModelImpl(context);
    }

    @Override
    public void initSetting() {
        FileCacheService service = new FileCacheService(context);
        Map<String, Object> map = (Map<String, Object>) service.getSharePreference("setting");
        if (map.isEmpty()) {
            map.put("audio_type", "wav");
            map.put("audio_rate", "16000");
            map.put("audio_subtitle", "srt");
            map.put("theme","2");
            model.initSetting(map, new OnCommonListener() {
                @Override
                public void onSuccess(String msg) {
                    view.showSuccess(msg,null);
                }

                @Override
                public void onError(String error) {
                    view.showError(error);
                }
            });
        }
    }
}
